<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="公告标题" prop="ntTitle">
        <el-input
          v-model="queryParams.ntTitle"
          placeholder="请输入公告标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开标时间" prop="openTime">
        <el-date-picker
          clearable
          v-model="queryParams.openTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开标时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="截止时间" prop="ntEndTime">
        <el-date-picker
          clearable
          v-model="queryParams.ntEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择投标截止时间"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          v-hasPermi="['purs:notice:add']"
          >新增</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="noticeList"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="招标项目" align="center" prop="bindCode" />
      <el-table-column label="公告标题" align="center" prop="ntTitle" />

      <el-table-column label="审批意见状态" align="center" prop="ntStatus" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['purs:notice:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['purs:notice:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listNotice,
  getNotice,
  delNotice,
  addNotice,
  updateNotice,
} from "@/api/purs/notice";

export default {
  name: "Notice",
  data() {
    return {
      // 遮罩层
      loading: true,
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招标公告表格数据
      noticeList: [],
      // 弹出层标题

      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ntTitle: null,
        ntEndTime: null,
        ntBeginTime: null,
        projectFunding: null,
        officeTime: null,
        openTime: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询招标公告列表 */
    getList() {
      this.loading = true;
      listNotice(this.queryParams).then((response) => {
        this.noticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ntId: null,
        bindCode: null,
        ntTitle: null,
        ntEndTime: null,
        ntBeginTime: null,
        remarks: null,
        ntStatus: null,
        createTime: null,
        projectFunding: null,
        officeTime: null,
        openTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ntIds = row.ntId || this.ids;
      this.$modal
        .confirm('是否确认删除招标公告编号为"' + ntIds + '"的数据项？')
        .then(function () {
          return delNotice(ntIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
